package models

import (
	"time"

	"github.com/astaxie/beego/validation"
)

type User struct {
	Id              int       `gorm:"primaryKey" json:"id" form:"id"`
	Name            string    `valid:"Required;" json:"name" form:"name"`
	Email           string    `valid:"Required;" form:"email"`
	Tel             string    `json:"tel" form:"tel"`
	City            string    `json:"city" form:"city"`
	Intro           string    `json:"intro" form:"intro"`
	Avatar          string    `json:"avatar" form:"avatar"`
	ProviderId      int       `json:"providerId" form:"providerId"`
	Provider        string    `json:"provider" form:"provider"`
	Password        string    `json:"password" form:"password"`
	RememberToken   string    `json:"rememberToken" form:"rememberToken"`
	Status          int       `json:"status" form:"status"`
	EmailVerifiedAt time.Time `json:"emailVerifiedAt" form:"emailVerifiedAt"`
	CreatedAt       time.Time `json:"createdAt" form:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt" form:"updatedAt"`
	DeletedAt       time.Time `json:"deletedAt"`
}

func (m *User) TableName() string {
	return TableName("users")
}

// 自定义验证规则
func (m *User) SelfValid() (msg interface{}) {
	valid := validation.Validation{}
	if b, _ := valid.Valid(m); !b {
		for _, err := range valid.Errors {
			return err.Message
		}
	}
	return nil
}
